package org.example.carsystem.controller;

import cn.hutool.core.date.DateTime;
import cn.hutool.json.JSONUtil;
import com.alibaba.excel.EasyExcel;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.example.carsystem.domain.SysDictData;
import org.example.carsystem.service.DictDataService;
import org.example.carsystem.service.DictTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/dict/data")
@CrossOrigin
public class DictDataController {
    @Autowired
    private DictDataService dictDataService;


    @GetMapping("/select")
    public Map<String,Object> dictDataSelect(@RequestParam("dictType")String dictType,
                                             @RequestParam(value = "dictLabel",required = false)String dictLabel,
                                             @RequestParam(value = "status",required = false)String status,
                                             @RequestParam(value = "pageNum",required = false,defaultValue = "1")Integer pageNum,
                                             @RequestParam(value = "pageSize",required = false,defaultValue = "5")Integer pageSize){
        System.out.println(dictLabel);
        PageHelper.startPage(pageNum,pageSize);
        List<SysDictData> list = dictDataService.dictDataSelect(dictType,dictLabel,status);
        PageInfo<SysDictData> info = new PageInfo<>(list);
        Map<String, Object> map = new HashMap<>();
        map.put("code",200);
        map.put("list",info);
        return map;
    }






    @RequestMapping("dlist")
    public List<SysDictData> dlist(@RequestBody SysDictData dataa){
        List<SysDictData> datas = dictDataService.listAll1(dataa);
        return datas;

    }






    @RequestMapping("updatedata")
    public Integer updatedata(@RequestBody SysDictData dataa){
        dataa.setUpdateTime(new DateTime());
        Integer updatetype=dictDataService.updatedata(dataa);

        return updatetype;
    }


    @RequestMapping("removetype/{dictType}")
    public Integer removedata(@PathVariable String dictType){
        Integer removetype=dictDataService.removedata(dictType);
        return removetype;

    }

    @RequestMapping("findxqlist")
    public List<SysDictData> findxqlist(@RequestParam String dictType){
        List<SysDictData> list=dictDataService.findxqlist(dictType);

        return list;
    }
    @RequestMapping("adddata")
    public Integer adddata(@RequestBody SysDictData data){
        System.out.println(data);
        data.setCreateTime(new DateTime());
        Integer addtype = dictDataService.adddata(data);


        return addtype;
    }
    //字典数据表
    @GetMapping("/datalist")
    public List<SysDictData> datalist(SysDictData dataa){
        System.out.println(dataa+"hhgiyfkjhvytdhycf");
        List<SysDictData> list=dictDataService.list(dataa);
        System.out.println(list);
        return list;

    }
}
